//
//  YJHGuidePageCollectionViewCell.m
//  NaoXinFaWu
//
//  Created by linzhijun on 16/5/25.
//  Copyright © 2016年 naoxin_Ltd. All rights reserved.
//

#import "YJHGuidePageCollectionViewCell.h"
#import "DMTabBarController.h"
#import "AppDelegate.h"

@interface YJHGuidePageCollectionViewCell()
/** 背景图片**/
@property (nonatomic ,weak)UIImageView *bgImageView;

/** 立即体验按钮**/
@property (nonatomic ,weak)UIButton *startBtn;
@end
@implementation YJHGuidePageCollectionViewCell
- (UIButton *)startBtn{
    if (!_startBtn){
        UIButton *button = [[UIButton alloc] init];
        button.nx_size=CGSizeMake(120, 40);
        [button setTitle:@"立 即 体 验" forState:UIControlStateNormal];
        [button setTitleColor:DMMainColor forState:UIControlStateNormal];
        button.titleLabel.font=[UIFont systemFontOfSize:18];
        button.backgroundColor=[UIColor whiteColor];
        button.layer.cornerRadius=5;
        button.layer.borderColor = DMMainColor.CGColor;
        button.layer.borderWidth = 1;
        button.clipsToBounds=YES;
        [self.contentView addSubview:button];
        
        _startBtn = button;
        _startBtn.center = CGPointMake(self.nx_width / 2, self.nx_height * 0.8f);
        [button addTarget:self action:@selector(startBtnOnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _startBtn;
}
// 当点击立即体验按钮的时候就会调用
- (void)startBtnOnClick:(UIButton *)button{
//    NSLog(@"_____");
    // 1.切换主框架
    // 2.切换界面有几种方法 1.push 2.tabbarVc 3.modal 如果要用modal新特性界面一直不会销毁 这样浪费类
    // 3.想让新特性界面销毁
    // 切换窗口的跟控制器
    DMTabBarController *tbVc=[[DMTabBarController alloc]init];
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    appDelegate.window.rootViewController = tbVc;
}
- (UIImageView *)bgImageView{
    if (!_bgImageView) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.bounds];
        [self.contentView addSubview:imageView];
        _bgImageView = imageView;
    }
    return _bgImageView;
}
- (void)setImage:(UIImage *)image{
    _image = image;
    
    // 给bgimageView 赋值
    self.bgImageView.image = image;
}
- (void)setIndexPath:(NSIndexPath *)indexPath count:(NSInteger)count{
    if (indexPath.item == count-1) { // 是最后一个cell
        // 当最后一个cell的时候添加立即体验按钮
        self.startBtn.hidden = NO;
    }else{
        // 不是最后一个cell
        // 隐藏立即体验按钮
        self.startBtn.hidden = YES;
    }
}
@end
